package tv.youxing.android.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.kymjs.rxvolley.RxVolley;
import com.kymjs.rxvolley.client.HttpCallback;
import com.kymjs.rxvolley.client.HttpParams;

import butterknife.BindView;
import butterknife.ButterKnife;
import tv.youxing.android.R;
import tv.youxing.android.custom.CustomToast;
import tv.youxing.android.utils.GsonUtils;
import tv.youxing.android.utils.StaticClass;
import tv.youxing.android.utils.UtilTools;


/**
 * 意见反馈
 */
public class FeedbackActivity extends BaseActivity {

    @BindView(R.id.phone)
    EditText phone;
    @BindView(R.id.content)
    EditText content;
    @BindView(R.id.btn)
    Button send;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        ButterKnife.bind(this);

        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String contact = UtilTools.getString(phone);
                String des = UtilTools.getString(content);

                if (contact.equals("") || des.equals("")) {
                    CustomToast.INSTANCE.showToast("请完善信息");
                    return;
                }else{
                    //post请求简洁版实现
                    HttpParams params = new HttpParams();
                    params.put("contact",UtilTools.getString(phone));
                    params.put("content",UtilTools.getString(content));

                    RxVolley.post(StaticClass.FEEDBACK, params, new HttpCallback() {
                        @Override
                        public void onSuccess(String t) {
                           Model model = GsonUtils.GsonToBean(t,Model.class);
                            CustomToast.INSTANCE.showToast(model.getStatus());
                            if (model.getCode() == 200) {
                                phone.setText("");
                                content.setText("");
                            }
                        }
                    });

                }
            }
        });
    }


    class Model {

        /**
         * status : 保存成功
         * result : {}
         * code : 200
         */

        private String status;
        private ResultBean result;
        private int code;

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public ResultBean getResult() {
            return result;
        }

        public void setResult(ResultBean result) {
            this.result = result;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public class ResultBean {
        }
    }
}

